package com.monkeys.Utils;

import java.text.DecimalFormat;
import java.util.Random;

public class RandomUtil {
    //随机生成车牌号
    public static String generateLicensePlate() {
        StringBuilder sb = new StringBuilder();

        // 省份和直辖市编码
        String[] provinces = {
                "京", "津", "沪", "渝", "冀", "豫", "云", "辽", "黑", "湘",
                "皖", "鲁", "新", "苏", "浙", "赣", "鄂", "桂", "甘", "晋",
                "蒙", "陕", "吉", "闽", "贵", "粤", "青", "藏", "川", "宁",
                "琼", "使", "领", "警", "学", "港", "澳"
        };
        Random random = new Random();
        int provinceIndex = random.nextInt(provinces.length);
        sb.append(provinces[provinceIndex]);

        // 城市编码（A-Z）
        char cityCode = (char) (random.nextInt(26) + 'A');
        sb.append(cityCode);

        // 字母和数字（0-9，A-Z）
        String characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        for (int i = 0; i < 5; i++) {
            int index = random.nextInt(characters.length());
            sb.append(characters.charAt(index));
        }

        return sb.toString();
    }

    //随机生成m-n的保留六位小数的数字
    public static Double generateRandomNumber6(int m, int n) {
        Random random = new Random();
        double randomNumber = random.nextDouble() * (n - m) + m;

        DecimalFormat decimalFormat = new DecimalFormat("#0.000000");
        String format = decimalFormat.format(randomNumber);

        return Double.valueOf(format);
    }


    //生成m-n的保留两位小数的数字
    public static Double generateRandomNumber2(Integer m, Integer n){
        double randomNum = Math.random() * (n - m + 1) + m;
        DecimalFormat df = new DecimalFormat("0.00");

        return Double.parseDouble(df.format(randomNum));
    }
}
